package sample;

import java.util.LinkedList;
import javafx.scene.control.TextArea;
public class SRT {
    //最短剩余时间优先shortest remaining time
    public SRT(LinkedList<PCB> pcblist,TextArea txtprocess) {
        int min=0,min_time,i;
        while (!pcblist.isEmpty()){
            for (int j = 0; j < pcblist.size(); j++) {
                min=0;
                min_time=pcblist.get(0).getTime();
                if (pcblist.get(j).getTime() < min_time && pcblist.get(j).getStatus() !=-1) {
                    min=j;
                    min_time=pcblist.get(j).getTime();
                }
            }
            pcblist.get(min).setTime(pcblist.get(min).getTime()-1);
            if (pcblist.get(min).getTime()<=0)
                //剩余时间为0则置为终止态
                pcblist.get(min).setStatus(-1);
            for ( i = 0; i < pcblist.size(); i++) {
                txtprocess.appendText(pcblist.get(i).print_pcb());
            }
            if (pcblist.get(min).getStatus()==-1)
            pcblist.remove(min);
            txtprocess.appendText("------------------------------------------------------------------------------------------\n");
        }
    }
}
